from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-17 14:02:33.362772
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 17, Jun, 2022
Time: 14:02:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5344
Nobs: 690.000 HQIC: -49.8973
Log likelihood: 8571.92 FPE: 1.70016e-22
AIC: -50.1262 Det(Omega_mle): 1.49365e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.302259 0.058440 5.172 0.000
L1.Burgenland 0.106179 0.038173 2.781 0.005
L1.Kärnten -0.109608 0.020169 -5.435 0.000
L1.Niederösterreich 0.203049 0.079911 2.541 0.011
L1.Oberösterreich 0.106326 0.078192 1.360 0.174
L1.Salzburg 0.257687 0.040768 6.321 0.000
L1.Steiermark 0.047476 0.053400 0.889 0.374
L1.Tirol 0.109205 0.043137 2.532 0.011
L1.Vorarlberg -0.054165 0.037428 -1.447 0.148
L1.Wien 0.036567 0.069178 0.529 0.597
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056204 0.123063 0.457 0.648
L1.Burgenland -0.036943 0.080387 -0.460 0.646
L1.Kärnten 0.041492 0.042472 0.977 0.329
L1.Niederösterreich -0.181291 0.168279 -1.077 0.281
L1.Oberösterreich 0.432175 0.164658 2.625 0.009
L1.Salzburg 0.288182 0.085849 3.357 0.001
L1.Steiermark 0.105442 0.112452 0.938 0.348
L1.Tirol 0.315748 0.090840 3.476 0.001
L1.Vorarlberg 0.028537 0.078816 0.362 0.717
L1.Wien -0.042361 0.145676 -0.291 0.771
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188335 0.029921 6.294 0.000
L1.Burgenland 0.089071 0.019545 4.557 0.000
L1.Kärnten -0.007714 0.010326 -0.747 0.455
L1.Niederösterreich 0.259277 0.040915 6.337 0.000
L1.Oberösterreich 0.139126 0.040034 3.475 0.001
L1.Salzburg 0.045735 0.020873 2.191 0.028
L1.Steiermark 0.024111 0.027341 0.882 0.378
L1.Tirol 0.090110 0.022086 4.080 0.000
L1.Vorarlberg 0.058509 0.019163 3.053 0.002
L1.Wien 0.114599 0.035419 3.236 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111813 0.030348 3.684 0.000
L1.Burgenland 0.043803 0.019824 2.210 0.027
L1.Kärnten -0.013460 0.010474 -1.285 0.199
L1.Niederösterreich 0.185446 0.041499 4.469 0.000
L1.Oberösterreich 0.305381 0.040606 7.521 0.000
L1.Salzburg 0.106368 0.021171 5.024 0.000
L1.Steiermark 0.108796 0.027731 3.923 0.000
L1.Tirol 0.101753 0.022402 4.542 0.000
L1.Vorarlberg 0.069694 0.019437 3.586 0.000
L1.Wien -0.020531 0.035925 -0.571 0.568
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.133241 0.055710 2.392 0.017
L1.Burgenland -0.050718 0.036391 -1.394 0.163
L1.Kärnten -0.044466 0.019227 -2.313 0.021
L1.Niederösterreich 0.148112 0.076180 1.944 0.052
L1.Oberösterreich 0.143073 0.074540 1.919 0.055
L1.Salzburg 0.285497 0.038864 7.346 0.000
L1.Steiermark 0.052746 0.050907 1.036 0.300
L1.Tirol 0.166581 0.041123 4.051 0.000
L1.Vorarlberg 0.096047 0.035680 2.692 0.007
L1.Wien 0.072220 0.065947 1.095 0.273
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061919 0.043994 1.407 0.159
L1.Burgenland 0.032471 0.028738 1.130 0.259
L1.Kärnten 0.051709 0.015183 3.406 0.001
L1.Niederösterreich 0.206910 0.060159 3.439 0.001
L1.Oberösterreich 0.296412 0.058864 5.036 0.000
L1.Salzburg 0.046018 0.030691 1.499 0.134
L1.Steiermark 0.008186 0.040201 0.204 0.839
L1.Tirol 0.137151 0.032475 4.223 0.000
L1.Vorarlberg 0.074937 0.028176 2.660 0.008
L1.Wien 0.084845 0.052078 1.629 0.103
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173584 0.052855 3.284 0.001
L1.Burgenland -0.002014 0.034526 -0.058 0.953
L1.Kärnten -0.063090 0.018242 -3.459 0.001
L1.Niederösterreich -0.088905 0.072275 -1.230 0.219
L1.Oberösterreich 0.195596 0.070720 2.766 0.006
L1.Salzburg 0.057070 0.036872 1.548 0.122
L1.Steiermark 0.242732 0.048298 5.026 0.000
L1.Tirol 0.497024 0.039015 12.739 0.000
L1.Vorarlberg 0.048657 0.033851 1.437 0.151
L1.Wien -0.058236 0.062567 -0.931 0.352
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163227 0.060083 2.717 0.007
L1.Burgenland -0.013690 0.039247 -0.349 0.727
L1.Kärnten 0.064385 0.020736 3.105 0.002
L1.Niederösterreich 0.195708 0.082159 2.382 0.017
L1.Oberösterreich -0.074007 0.080391 -0.921 0.357
L1.Salzburg 0.210357 0.041914 5.019 0.000
L1.Steiermark 0.138007 0.054902 2.514 0.012
L1.Tirol 0.063384 0.044351 1.429 0.153
L1.Vorarlberg 0.121980 0.038480 3.170 0.002
L1.Wien 0.133074 0.071123 1.871 0.061
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.369701 0.034825 10.616 0.000
L1.Burgenland 0.004812 0.022748 0.212 0.832
L1.Kärnten -0.023264 0.012019 -1.936 0.053
L1.Niederösterreich 0.216117 0.047620 4.538 0.000
L1.Oberösterreich 0.203750 0.046595 4.373 0.000
L1.Salzburg 0.044159 0.024294 1.818 0.069
L1.Steiermark -0.017241 0.031822 -0.542 0.588
L1.Tirol 0.105346 0.025706 4.098 0.000
L1.Vorarlberg 0.069287 0.022304 3.107 0.002
L1.Wien 0.029362 0.041224 0.712 0.476
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037046 0.130972 0.189263 0.151116 0.112319 0.094885 0.052767 0.216595
Kärnten 0.037046 1.000000 -0.017372 0.133166 0.055223 0.092481 0.437502 -0.054797 0.092905
Niederösterreich 0.130972 -0.017372 1.000000 0.333176 0.139381 0.291664 0.084701 0.171269 0.310555
Oberösterreich 0.189263 0.133166 0.333176 1.000000 0.226218 0.320680 0.172453 0.157224 0.264043
Salzburg 0.151116 0.055223 0.139381 0.226218 1.000000 0.138397 0.112607 0.137028 0.132887
Steiermark 0.112319 0.092481 0.291664 0.320680 0.138397 1.000000 0.145513 0.124948 0.069784
Tirol 0.094885 0.437502 0.084701 0.172453 0.112607 0.145513 1.000000 0.106966 0.143432
Vorarlberg 0.052767 -0.054797 0.171269 0.157224 0.137028 0.124948 0.106966 1.000000 0.004868
Wien 0.216595 0.092905 0.310555 0.264043 0.132887 0.069784 0.143432 0.004868 1.000000